/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tbquestion_bll;

import dalInterface.DALFactory;
import dalfactory.SDALFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.Naming;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import qserver.QServer;

/**
 *
 * @author salm
 */
public class TBQuestion_BLL {

    private static String DALHost;
    private static int DALPort;
    private static String BLLHost;
    private static int BLLPort;
    
    private static void readHost()
    {
        // NEED TABLE
        try
        {
            Properties p = new Properties();
            p.load(new FileInputStream("NetworkConfig.ini"));
            
            DALHost = p.getProperty("DALHost");
            DALPort = Integer.parseInt(p.getProperty("DALPort"));
            BLLPort = Integer.parseInt(p.getProperty("BLLPort"));
            
            (new BLLFrame()).setVisible(true);
        }
        catch (IOException ioEx)
        {
            DALHost = "rmi://localhost";
            DALPort = 2013;
            BLLPort = 2014;
        }
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            readHost();
            DALFactory dalFact = (DALFactory) Naming.lookup(String.format("%s:%d/%s", DALHost, DALPort, "DALFactory"));
            SDALFactory.initInstance(dalFact);
            
            QServer qServer = new QServer(BLLPort);
            qServer.startServer();
        } catch (RemoteException | NotBoundException | MalformedURLException ex) {
            Logger.getLogger(TBQuestion_BLL.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(TBQuestion_BLL.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
